package cool.taomu.toolkit.demo

import com.google.auto.service.AutoService
import com.google.common.eventbus.EventBus
import com.google.inject.AbstractModule
import com.google.inject.multibindings.OptionalBinder
import cool.taomu.toolkit.TaomuConfigure
import cool.taomu.toolkit.demo.stock.listener.MacdSignalListener
import cool.taomu.toolkit.demo.stock.listener.RsiSignalListener
import cool.taomu.toolkit.platform.inter.AbsPlatform
import cool.taomu.toolkit.platform.inter.IPlatform
import cool.taomu.toolkit.provider.EventBusProvider
import org.slf4j.LoggerFactory

@AutoService(IPlatform)
class DemoPlugin extends AbsPlatform {

	val static LOG = LoggerFactory.getLogger(DemoPlugin);

	override note() {
		"demo"
	}

	override packages() {
		#["cool.taomu.toolkit.demo.controller", "cool.taomu.toolkit.demo.stock.controller"].join(",")
	}

	override module(TaomuConfigure configure) {
		new AbstractModule() {
			override configure() {
				OptionalBinder.newOptionalBinder(
					binder(),
					EventBus
				).setDefault.toProvider(EventBusProvider).asEagerSingleton
				bind(MacdSignalListener).asEagerSingleton
				bind(RsiSignalListener).asEagerSingleton
			}
		}
	}

	override start() {
	}

	override init() {
		var eventbus = this.context.getInstance(EventBus) as EventBus
		eventbus.register(this.context.getInstance(MacdSignalListener))
		eventbus.register(this.context.getInstance(RsiSignalListener))
	}
}
